
package com.etc

import org.apache.spark.{SparkConf, SparkContext}

object top3 {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setAppName("topN").setMaster("local")
    val sc = new SparkContext(conf)
    val data = sc.textFile("E:\\input\\score.txt")
    val unit = data.map { line =>
      (line.split(" ")(0), line.split(" ")(1)
      )
    }
    val string = unit.groupByKey()

    val score = string.map(a => {
      val classname = a._1
      val top3 = a._2.toBuffer.sortWith(_>_).take(3)
      Tuple2(classname, top3)
    })
    score.foreach(a => {
      val name = a._1
      println(name)
      for (s <- a._2) {
        println( s)
      }

      println("********************")
    })
  }
}
